import json

from channels.generic.websocket import AsyncWebsocketConsumer


class ChatConsumer(AsyncWebsocketConsumer):
    async def connect(self) -> None:
        await self.accept()

    async def disconnect(self, close_code) -> None:
        pass

    async def receive(self, text_data) -> None:
        print(text_data)
        await self.send(text_data=json.dumps({
            "message": text_data,
        }))
